<?php
use yii\widgets\LinkPager;
use yii\helpers\Url;
?>

<?= $this->render('header'); ?>

<div class="row borB">
	<div class="container">
		<ul class="nav nav-tabs mt10 smNav">
			<li><a href="<?= Url::to(['make', 'type' => 1]) ?>">店铺预约</a></li>
			<li class="active"><a href="javascript:;" style="color: #575757;">APP预约</a></li>
		</ul>
	</div>
</div>

<div id="service-log" class="container mt20">
	<div class="table-responsive">
		<?php if(empty($list)){?>
		<table class="table table-bordered">
			<thead>
			<tr>
				<th>会员</th>
				<th>预约项目</th>
				<th>服务时间</th>
				<th>记录时间</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
			<tr>
				<td colspan="6" align="center"><img src="<?=Yii::getAlias('@web/backend/img/nodata.gif');?>"></td>
			</tr>
			</tbody>
		</table>
		<?php }else{?>
		<table class="table table-bordered">
			<thead>
			<tr>
				<th>会员</th>
				<th>预约项目</th>
				<th>服务时间</th>
				<th>记录时间</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody>
			<?php foreach($list as $val): ?>
			<tr>
				<td class="exc">
					<div class="exc-con">
						<div><?= $val['order_member_name'] ?></div>
						<div><?= $val['order_member_phone'] ?></div>
					</div>
				</td>
				<td><?= $val['order_item'] ?></td>
				<td><?= substr($val['order_time'], 0, 16) ?></td>
				<td><?= substr($val['add_time'], 0, 10) ?></td>
				<td class="order_c<?= $val['order_id'] ?>">
					<?php
						if ($val['order_status'] == 1) {
							echo '预约中';
						} elseif ($val['order_status'] == 2) {
							echo '已到店';
						} else {
							echo '未到店';
						}
					?>
				</td>
				<td class="order_s<?= $val['order_id'] ?>">
					<?php if ($val['order_status'] == 1){ ?>
						<a class="btnBor" href="javascript:;" onclick="openPage(<?= $val['order_id'] ?>)">已到店</a>
						<a class="btnBor" href="javascript:;" onclick="exitShop(<?= $val['order_id'] ?>)">未到店</a>
					<?php } else { ?>
						<a class="btnBor active" href="javascript:;">已到店</a>
						<a class="btnBor active" href="javascript:;">未到店</a>
					<?php } ?>
				</td>
			</tr>
			<?php endforeach; ?>

			</tbody>
		</table>
		<?php }?>
	</div>
	<div class="page" style="text-align: center">
		<?= LinkPager::widget([
			'pagination' => $page,
			// 'hideOnSinglePage' => true
		]); ?>
	</div>

</div>

<script>
	<?php $this->beginBlock('js_index') ?>

	// 修改状态为未到店
	function exitShop(order_id)
	{
		$.get("<?= Url::to(['editserviceorder']) ?>", {order_id:order_id, status:0},
		function(status) {
			if (status == 1) { // 修改成功
				var obj_c = $('.order_s' + order_id).find('a');
				obj_c.addClass('active');
				obj_c.removeAttr('onclick');
				$('.order_c' + order_id).html('未到店');

		 		layer.alert('修改成功！', {icon:1});
			} else {
				layer.alert('修改失败！', {icon:2});
			}
		});
	}

	function openPage(order_id)
	{
		layer.open({
			type: 2,
			area: ['700px', '530px'],
			title:'',
			fix: true, //不固定
			maxmin: true,
			content: '<?= Url::to(['appstate']) ?>?order_id=' + order_id
		});
	}

	<?php $this->endBlock() ?>
	<?php $this->registerJs($this->blocks['js_index'], $this::POS_END); ?>
</script>